package com.stable.actor.core;

import java.util.function.Supplier;

/**
 * Actor创建配置 - 类似Akka的Props
 */
public class Props {
    private final Supplier<StableActor> actorSupplier;

    private Props(Supplier<StableActor> actorSupplier) {
        this.actorSupplier = actorSupplier;
    }

    // 创建Props - 类似Akka API
    public static Props create(Supplier<StableActor> actorSupplier) {
        return new Props(actorSupplier);
    }

    public static Props create(Class<? extends StableActor> actorClass) {
        return new Props(() -> {
            try {
                return actorClass.getDeclaredConstructor().newInstance();
            } catch (Exception e) {
                throw new RuntimeException("创建Actor实例失败: " + actorClass.getName(), e);
            }
        });
    }

    public StableActor createActor() {
        return actorSupplier.get();
    }
}
